#include <stdio.h>
#include <string.h>

// 驼峰命名法
//下划线命名法
// My_str_len
long MyStrLen(const char *s)
{
   long len = 0;
   while( *(s++) != '\0')
   len++;
   return len;  
}

int MyStrcmp(const char *s1,const char *s2)
{
    while( *s1 == *s2 && *s1 != '\0'&& *s2 != '\0')
    {
        s1++;
        s2++;
    }
    return *s1 - *s2;

}


void MyStrncpy(char *dest ,const char* src,int n)
{
   while (*src != '\0'&& n-- > 0)
      *dest++ = *src++;
   *dest = '\0';
 
}
void MyStrcat(char *dest,const char *src)
{
    while(*dest !='\0')
         dest++;
    // 调用已有接口
    strcpy(dest,src);
}

char* MyStrstr(const char* dest,const char *src)
{
    long dlen = strlen(dest);
    long slen = strlen(src);
    for(int i = 0; i < dlen-slen;i++)
    {
        if(strncmp(dest+i,src,slen)==0)
        {
            return (char*)(dest + i);
        }
    }
    return NULL;
}
char * MyStrtok(char *src,const char *delim)
{   
    static char *dest = NULL;
    if(src != NULL)
    {
       dest = strstr(src,delim);
       //没有找到匹配的字符串
        if(dest == NULL)
        {
            return src;
        }
  
        *dest = '\0';
        dest = dest + strlen(delim);
        return src;
    }
    else
    {
      if(dest == NULL)
      {
        return NULL;
      }
      return MyStrtok(dest,delim); //递归 ； 自己调用自己
      
    }
    
}
int main()
{
    char  s1[20] = "hello,world";
    char *s2 = ",";
    char *dest = MyStrtok(s1,s2);
    while(dest != NULL)
    {
       printf("%s\n",dest);
       dest = MyStrtok(NULL,s2);
    }
 
    // printf("%p %p\n",s1,MyStrstr(s1,s2));

    return 0;
}